package cn.tedu.mall.front.service.impl;

import cn.tedu.mall.common.restful.JsonPage;
import cn.tedu.mall.front.service.IFrontProductService;
import cn.tedu.mall.pojo.product.vo.*;
import cn.tedu.mall.product.service.front.IForFrontAttributeService;
import cn.tedu.mall.product.service.front.IForFrontSkuService;
import cn.tedu.mall.product.service.front.IForFrontSpuService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FrontProductServiceImpl implements IFrontProductService {

    //依旧需要远程调用product服务，进行数据的查询
    @DubboReference
    private IForFrontSpuService dubboFrontSpuService;
    //sku
    @DubboReference
    private IForFrontSkuService dubboFrontSkuService;
    //商品参数的选项(attribute)
    @DubboReference
    private IForFrontAttributeService dubboFrontAttributeService;

    @Override
    public JsonPage<SpuListItemVO> listSpuByCategoryId(Long categoryId, Integer page, Integer pageSize) {
        JsonPage<SpuListItemVO> list = dubboFrontSpuService.listSpuByCategoryId(categoryId, page, pageSize);
        return list;
    }
    //根据spuId查询spu信息
    @Override
    public SpuStandardVO getFrontSpuById(Long id) {
        SpuStandardVO spuStandardVO = dubboFrontSpuService.getSpuById(id);
        return spuStandardVO;
    }
    //根据spuId查询sku列表
    @Override
    public List<SkuStandardVO> getFrontSkusBySpuId(Long spuId) {
        List<SkuStandardVO> skuStandardVOS = dubboFrontSkuService.getSkusBySpuId(spuId);
        return skuStandardVOS;
    }
    //根据spuId查询spuDetail
    @Override
    public SpuDetailStandardVO getSpuDetail(Long spuId) {
        SpuDetailStandardVO spuDetailStandardVO = dubboFrontSpuService.getSpuDetailById(spuId);
        return spuDetailStandardVO;
    }
    //根据spuId查询当前商品所有参数选项
    @Override
    public List<AttributeStandardVO> getSpuAttributesBySpuId(Long spuId) {
        //是一个五表联查
        List<AttributeStandardVO> attributeStandardVOS = dubboFrontAttributeService.getSpuAttributesBySpuId(spuId);
        return attributeStandardVOS;
    }
}
